package com.zc.framework.utils;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bouncycastle.util.encoders.Hex;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by User on 2016/11/22.
 */
public class MD5Utils {

    private static final Logger logger = LogManager.getLogger(MD5Utils.class);

    public static String getMD5(String src){
        try {
            // 创建加密对象
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");//提供信息摘要算法的功能
            byte[] md5bytes = messageDigest.digest(src.getBytes());//使用指定的 byte 数组对摘要进行最后更新，然后完成摘要计算
            String encrypt = Hex.toHexString(md5bytes);
            return encrypt;
        } catch (NoSuchAlgorithmException e) {
            logger.info("MD5Utils.getMD5", e);
        }
        return null;
    }
}
